package com.ck.demo;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class CopyOnWriteArrayListDemo {
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        //ArrayBlockingQueue<Integer> list = new ArrayBlockingQueue<>(51);
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i <= 50; i++) {
            int finalI = i;
            String threadStr = String.valueOf(i);
            Thread thread =new Thread(() -> {
                list.add(finalI);
                log.info("time:{},list:{}",(System.currentTimeMillis()-startTime)+"ms", list);
            },threadStr);
            thread.start();
            try {
                thread.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
